 var start=0,page=1,showNumber=11;
 var isload = true
$(function() {
		var contextPath = $("#contextPath").val();
		var bonusid = $("#bonusid");
		var bonus=0;   //累计收入
		var totalbonus = $("#totalbonus");
		
		if(totalbonus.text() == 0 ){
			$(".bonus_cn").after('<div class=tc mt10 f14>您好！您目前的累计收入为零，继续加油哦！</div>');
			/*layer.open({
			    title: '提示',
			    content: '您好！您目前的累计收入为零，继续加油哦！',
			    btn: ['我知道了'],
			    yes: function(index){
			    	location.href=contextPath+"/user/myvip";
			    }
			});*/
		}else{
			bonusInit();
		}
		function bonusInit(){
			
			$.ajax({
				url:"getBonus",
				type:"post",
				async:true,
				dataType:"json",
				data:{start:start,showNumber:showNumber},
				success : function(data, textStatus) {
					var state = data.result.state;
					if(state == 1){
						$.each(data.bonusMap,function(i,v){
							var html ='';
							bonus = bonus + v.bonus; //累计收入
							
							var bonusType;
							var name;
							var level='';
							//判断好友等级
							if(v.friend_level==1){
								level="一级好友";
							}else if(v.friend_level==2){
								level="二级好友";
							}
						    //判断奖励类型
							if(v.type=='01'){
								level='';
								bonusType='省级代理佣金';
							}else if(v.type=='02'){
								level='';
								bonusType='区县代理佣金';
							}else if(v.type=='04'){
								bonusType='一级佣金';
							}else if (v.type=='05'){
								bonusType='二级佣金';
							}else if (v.type=='06'){
								level='';
								bonusType='实体店佣金';
							}
			
							//类型为商品
							if(v.type==02){
								html +='<div class="ui_cell"><div class="ui_cell_bd"><div class="df bonus_cn" >   <div class="vip_name bonus_info"> <p> <span class="dib vm c_bright">'+
								v.title+'</span> </p><p class="bonus_info_txt">'+bonusType+'</p><p class="bonus_info_txt">'+v.create_time+'</p></div><div class="vip_grade"> <span class="dib vm">￥<em class="n">'+v.bonus+'</em></span> <div class="dib_vm"></div>  </div> </div></div></div>  ';
							}else{
								html+='<div class="ui_cell"><div class="ui_cell_bd"><div class="df bonus_cn" > <div class="vip_name bonus_info"> <p> <span class="dib vm c_bright">'+v.title+'</span>';
									
									if(level != ''){
										html+='<span class="vip_type dib vm">'+level+'</span>';
									}
									html+='</p><p class="bonus_info_txt">'+bonusType+'</p><p class="bonus_info_txt">'+v.create_time+'</p></div><div class="vip_grade"> <span class="dib vm">￥<em class="n">'+v.bonus+'</em></span> <div class="dib_vm"></div>  </div> </div></div></div>  ';
							}
							bonusid.append(html);	  
						});
					
						
						start=page*showNumber;
						page++;
						if(data.bonusMap.length == showNumber){
							isload = true;	
						}
			
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					layer.open({
					    content:textStatus,
					    time: 2
					});
				}
				
				
				
			});	
		}  
		
		//滑动切换页面
		dropload.scroll(function(t){
			if(t<5&&isload){
				$(".lodingStyle").show();
				isload = false;
				bonusInit();
			}

		 });
		
		
});

